package com.wingscode.modules.app.utils;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import com.wingscode.modules.app.form.SecurityCodeFrom;
import com.wingscode.util.MyUtilJson;

/**
 * @author CrazyHuskar
 * caeat at 2019/7/30  15:48
 */
public class SmsUtil {
    public SecurityCodeFrom getSecurityCode(String phone, String code) throws ClientException {
//    	DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GBASaAmFKvWY2JtByLB", "1Kxqimm32K7rUQZ8VKFrR5aHDGqMJ0");
//    	IAcsClient client = new DefaultAcsClient(profile);
//
//    	CommonRequest request = new CommonRequest();
//    	request.setSysMethod(MethodType.POST);
//    	request.setSysDomain("dysmsapi.aliyuncs.com");
//    	request.setSysVersion("2017-05-25");
//    	request.setSysAction("SendSms");
//    	request.putQueryParameter("RegionId", "cn-hangzhou");
//    	request.putQueryParameter("PhoneNumbers", phone);
//    	request.putQueryParameter("SignName", "智慧屯军营");
//    	request.putQueryParameter("TemplateCode", "SMS_192340588");
//    	request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");
//
//    	CommonResponse response = client.getCommonResponse(request);
//
//		return MyUtilJson.parseObject(response.getData(), SecurityCodeFrom.class);

		DefaultProfile profile = DefaultProfile.getProfile("default", "LTAI6JBjG5qjNNyv", "aafMqhVu4zjVVUjqADPEH0fOqoIYPy");
    	IAcsClient client = new DefaultAcsClient(profile);

    	CommonRequest request = new CommonRequest();
    	request.setSysMethod(MethodType.POST);
    	request.setSysDomain("dysmsapi.aliyuncs.com");
    	request.setSysVersion("2017-05-25");
    	request.setSysAction("SendSms");
    	request.putQueryParameter("RegionId", "default");
    	request.putQueryParameter("PhoneNumbers", phone);
    	request.putQueryParameter("SignName", "人才壹佰");
    	request.putQueryParameter("TemplateCode", "SMS_171235025");
    	request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}");

    	CommonResponse response = client.getCommonResponse(request);

		return MyUtilJson.parseObject(response.getData(), SecurityCodeFrom.class);
    }
}
